package warmachineroster.grapheditor.editpart;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;

import warmachineroster.RosterElement;
import warmachineroster.UnitRosterElement;
import warmachineroster.grapheditor.figure.BaseRosterElementFigure;
import warmachineroster.grapheditor.figure.UnitRosterElementFigure;
import warmachineroster.grapheditor.policy.RosterElementComponentEditPolicy;
import warmachineroster.grapheditor.policy.UnitFlowLayoutEditPolicy;

public class UnitRosterElementEditPart extends RosterElementEditPart {

	@Override
	protected IFigure createFigure() {
		BaseRosterElementFigure figure = new UnitRosterElementFigure(getElementName(), getUnitType().getArmyList().getCode());
		return figure;
	}

	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new UnitFlowLayoutEditPolicy());
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new RosterElementComponentEditPolicy());
	}
	
	public UnitRosterElement getUnitRosterElement(){
		return (UnitRosterElement) getModel();
	}
	
	@Override
	protected List<RosterElement> getModelChildren() {
		return getUnitRosterElement().getUnitAttachment();
	}

	@Override
	protected void refreshVisuals() {
		super.refreshVisuals();
		UnitRosterElementFigure figure = getUnitRosterElementFigure();
		figure.setUnitSize(getUnitRosterElement().getModelCount());
	}

	@Override
	public IFigure getContentPane() {
		UnitRosterElementFigure figure = getUnitRosterElementFigure();
		return figure.getBattleGroupFigure();
	}

	protected UnitRosterElementFigure getUnitRosterElementFigure() {
		UnitRosterElementFigure figure = (UnitRosterElementFigure) getFigure();
		return figure;
	}

	
	
}
